package com.spa.interfaces.admin;

import com.spa.application.command.admin.AdminCarouselAddCommand;
import com.spa.application.command.admin.AdminCarouselEditCommand;
import com.spa.application.dto.PageResult;
import com.spa.application.dto.admin.AdminCarouselDTO;
import com.spa.application.query.BaseIdQuery;
import com.spa.application.query.admin.AdminCarouselQuery;
import com.spa.application.service.admin.AdminCarouselApplicationService;
import com.spa.infrastructure.common.ResponseMessage;
import com.spa.interfaces.BaseController;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/admin/carousel")
public class AdminCarouselController extends BaseController {

    @Resource
    private AdminCarouselApplicationService adminCarouselApplicationService;

    @PostMapping("add")
    public ResponseMessage add(@Validated @RequestBody AdminCarouselAddCommand command) {
        adminCarouselApplicationService.add(command);
        return responseHelper.success();
    }

    @PostMapping("edit")
    public ResponseMessage edit(@Validated @RequestBody AdminCarouselEditCommand command) {
        adminCarouselApplicationService.edit(command);
        return responseHelper.success();
    }

    @PostMapping("page")
    public ResponseMessage<PageResult<AdminCarouselDTO>> page(@Validated @RequestBody AdminCarouselQuery query) {
        return responseHelper.success(adminCarouselApplicationService.page(query));
    }

    @PostMapping("onOffShow")
    public ResponseMessage onOffShow(@Validated @RequestBody BaseIdQuery baseIdQuery) {
        adminCarouselApplicationService.onOffShow(baseIdQuery);
        return responseHelper.success();
    }

    @PostMapping("del")
    public ResponseMessage del(@Validated @RequestBody BaseIdQuery baseIdQuery) {
        if(adminCarouselApplicationService.delById(baseIdQuery)){
            return responseHelper.success();
        }
        return responseHelper.fail();
    }

}
